﻿@model BlogThread
@{
    IEnumerable<Comment> comments = ViewData.Get<IEnumerable<Comment>>("Comments", new List<Comment>());
    string spaceKey = UserIdToUserNameDictionary.GetUserName(Model.UserId);
    string url = SiteUrls.Instance().BlogDetail(spaceKey, Model.ThreadId);
}
<li class="tn-list-item tn-helper-clearfix tn-border-gray tn-border-bottom spb-blog-item">
    <div class="tn-list-item-area-left">
        @{
            HyperLinkTarget hyperLinkTarget;
            if (UserContext.CurrentUser != null && Model.UserId == UserContext.CurrentUser.UserId)
            {
                hyperLinkTarget = HyperLinkTarget._self;
            }
            else
            {
                hyperLinkTarget = HyperLinkTarget._blank;
            }
        }
        @Html.ShowUserAvatar(Model.User, AvatarSizeType.Small, true, hyperLinkTarget)
    </div>
    <div class="tn-list-item-area-main">
        @Html.ActivityOperation(ViewData.Get<long>("ActivityId", 0))
        <div class="tnc-dynamic-title">
            @Html.Link(Model.Author, SiteUrls.Instance().SpaceHome(Model.UserId), null, new { @class = "tn-author" }, hyperLinkTarget)
            @Html.IdentificationType(Model.UserId)
            @(comments.Count() == 0 ? "发布了日志" : "的日志")
            @Html.Link(Model.ResolvedSubject, url, Model.Subject, new { @class = "tn-title" }, HyperLinkTarget._blank)
            @if (comments.Count() != 0)
            {
                @:被
                @Html.Raw(string.Join("、", comments.Select(n => new { Author = n.Author, UserId = n.UserId }).Distinct().Select(n => Html.Link(n.Author, SiteUrls.Instance().SpaceHome(Model.UserId), null, new { @class = "tn-commenter" }, hyperLinkTarget).ToString() + Html.IdentificationType(n.UserId).ToString())))
                <text>评论了</text>
            }
        </div>
        <p class="tnc-dynamic-box">
            @{
                string body = HtmlUtility.TrimHtml(Model.GetBody(), 105);
            }
            @body
        </p>
        @{
            IEnumerable<Attachment> attachments = ViewData.Get<IEnumerable<Attachment>>("Attachments", new List<Attachment>());
            int totalCount = 0;
            if (attachments != null)
            {
                totalCount = attachments.Count();
                attachments = attachments.Count() > 7 ? attachments.Take(7) : attachments;
            }
        }
        @if (attachments != null && attachments.Count() > 0)
        {
            <div class="tnc-dynamic-imgbox">
                <a href="@url" class="tnc-imgbox-bigshow" target="_blank">
                    <img alt="@attachments.ElementAt(0).FriendlyFileName" src="@SiteUrls.Instance().ImageUrl(attachments.ElementAt(0), attachments.ElementAt(0).TenantTypeId, ImageSizeTypeKeys.Instance().Original())" width="400" /></a>
                <div class="tnc-imgbox_preview">
                    @for (int i = 1; i < attachments.Count(); i++)
                    {
                        <a href="@url" target="_blank">
                            <img width="60" src="@SiteUrls.Instance().ImageUrl(attachments.ElementAt(i), attachments.ElementAt(i).TenantTypeId, ImageSizeTypeKeys.Instance().Small())"/></a>
                                            if (i == attachments.Count() - 1)
                                            {
                        <a href="@url" class="tnc-imgbox-float tn-bg-light" target="_blank">共 @totalCount
                            张</a>
                                            }
                    }
                </div>
            </div>
        }
        <p class="tnc-dynamic-box tnc-textsize-small">
            @{
                string replay = Model.CommentCount > 0 ? string.Format("评论（{0}）", Model.CommentCount) : "评论";
            }
            @Html.Link(replay, url + "#comment", replay, new { @class = "tnc-mrf" }, HyperLinkTarget._blank)
            <em class="tn-date tn-text-note">@Model.DateCreated.ToFriendlyDate()</em>
        </p>
        @if (comments.Count() > 0)
        {
            <div class="tnc-dynamic-commentbox spb-status-textarea tnc-textsize-small spb-bar-comment">
                <div class="tn-widget tn-bubble tn-bubble-arrow-top">
                    <div class="tn-bubble-arrow">
                        <b class="tn-arrow-b1 tn-border-gray"></b><b class="tn-arrow-b2 tn-widget-bubble">
                        </b>
                    </div>
                    <div class="tn-bubble-content tn-widget-content tn-border-gray tn-border-top">
                        <ul class="tn-comments">
                            @foreach (var comment in comments)
                            {
                                if(!comment.IsPrivate)
                                {
                                <li class="tn-comment-item">
                                    <div class="tn-comment tn-helper-clearfix tn-hover">
                                        <div class="tn-comment-avatar">
                                            @Html.ShowUserAvatar(comment.UserId, AvatarSizeType.Small, true, hyperLinkTarget)
                                        </div>
                                        <div class="tn-comment-info">
                                            <div class="tn-commentator">
                                                @Html.Link(comment.Author, SiteUrls.Instance().SpaceHome(comment.UserId), null, new { @class = "tn-user-name" }, hyperLinkTarget)
                                                <em class="tn-text-note tn-date">@comment.DateCreated.ToFriendlyDate()</em></div>
                                            <p>
                                                @HtmlUtility.TrimHtml(comment.Body, 88)</p>
                                        </div>
                                    </div>
                                </li>
                                 }
                            }
                        </ul>
                    </div>
                </div>
            </div>
        }
    </div>
</li>
